import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/gaps.dart';

import '../../viewmodel/device/device_repair_record_view_model.dart';

class DeviceRepairRecordFragment extends BaseStatefulMvvmWidget {
  final String? id;
  final String? content;

  DeviceRepairRecordFragment({this.id, this.content});

  @override
  State<StatefulWidget> createState() => _DeviceRepairRecordState();
}

class _DeviceRepairRecordState extends BaseMvvmListState<
    DeviceRepairRecordViewModel, DeviceRepairRecordFragment> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return ExpandItemWidget(
        contentWidget: IconTitleTextWidget(
          '维保时间',
          showArrow: false,
          text: item.optDate??"",
          height: 40,
          padding: EdgeInsets.zero,
        ),
        childWidget: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Gaps.line,
            Container(height: 15,),
            itemContent(title: '设备名称', value: item.equipmentName??""),
            itemContent(title: '设备编号', value: item.equipmentSerialNumber??""),
            itemContent(title: '维保状态', value: item.statusName??""),
            itemContent(title: '操作时间', value: item.createdDate??""),
            itemContent(title: '维保人员', value: item.optName??""),
            CommonText('维保内容'),
            Container(height: 10,),
            CommonText(item.content??""),
            Container(height: 10,),

          ],
        ).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16)));
  }

  @override
  DeviceRepairRecordViewModel createViewModel() {
    return DeviceRepairRecordViewModel(context,content: widget.content,id: widget.id);
  }

  @override
  Widget get separatorDivider => Gaps.line;

  Widget itemContent({required String title,required String value}){
    return Row(
      children: [
        CommonText(title).setWeight(1),
        CommonText(value)
      ],
    ).addToContainer(margin: EdgeInsets.only(bottom: 10));
  }
}
